﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using CharacterTrailLibrary.Exceptions;
using DevExpress.XtraEditors;

namespace CharacterTrailClient.Query.Item
{
    public partial class StringLike : DevExpress.XtraEditors.XtraUserControl, IQueryItem
    {
        public StringLike()
        {
            InitializeComponent();
        }

        public string Field { get; set; }

        public string GetCondition()
        {
            string condition = " and 1=1 ";

            if (String.IsNullOrEmpty(Field))
                throw new AppException("字段属性没有设置！");

            if (this.textEdit1.EditValue != null && !String.IsNullOrEmpty(this.textEdit1.Text.Trim()))
            {
                condition += (String.Format(" and {0}  like '%{1}%'", Field, textEdit1.Text.Trim()));
            }
    
            return condition;
        }

        [ToolboxItem(true)]
        public string Label
        {
            get
            {
                return this.labelText.Text;
            }
            set
            {
                this.labelText.Text = value;
            }
        }
    }
}
